package com.cjjd.c.feature.mine.message;

import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.cjjd.c.R;
import com.cjjd.c.base.MyBaseAdapter;
import com.cjjd.c.bean.MessageItem;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * ----------------------------------
 * Created by xyd on 2017/8/14.
 * <p/>
 * 描  述：
 * <p/>
 * 修订历史:
 * ----------------------------------
 */

public class MessageAdapter extends MyBaseAdapter {


    public MessageAdapter(FragmentActivity mContext) {
        super(mContext);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_message, parent, false);
            //convertView = View.inflate(mContext,R.layout.item_message,parent);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        MessageItem item = (MessageItem) getItem(position);
        viewHolder.tvMessageType.setText(item.typeName);
        if (item.enterTime != null && item.enterTime.length() > 10) {
            viewHolder.tvMessageTime.setText(item.enterTime.substring(0, 10));
        } else {
            viewHolder.tvMessageTime.setText(item.enterTime);
        }
        viewHolder.tvMessageContent.setText(item.messageCenterStr);

        return convertView;
    }


    static class ViewHolder {
        @Bind(R.id.iv_notify)
        ImageView ivNotify;
        @Bind(R.id.tv_message_type)
        TextView tvMessageType;
        @Bind(R.id.tv_message_time)
        TextView tvMessageTime;
        @Bind(R.id.tv_message_content)
        TextView tvMessageContent;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
